public class p3 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		long bigN = 600851475143L; // 12 digit number
		int max = 0;

		while (bigN > 1) {
			for (long i = 3; i < bigN; i++) {
				if (i % 2 == 0) {
					// special case for bigN!
					continue;
				}

				if (bigN % i == 0 && isPrime(i)) {
					if (i > max) {
						max = (int) i;
					}
					bigN /= i;

					// System.out.println("i: " + i + ", bigN: " + bigN);
					break;
				}
			}
			if (isPrime(bigN)) {
				if (bigN > max) {
					max = (int) bigN;
				}
				break;
			}
		}
		System.out.println(max);

		// advanced method
		// decrease searching ranges
		// do not need primality test
		bigN = 600851475143L; // 12 digit number
		long factor = 1;
		long lastFactor = 1;
		long maxFactor = (long) Math.sqrt(bigN);

		if (bigN % 2 == 0) {
			lastFactor = 2;
			do {
				bigN /= 2;
			} while (bigN % 2 == 0);
		}

		factor = 3;
		while (bigN > 1 && factor <= maxFactor) {
			if (bigN % factor == 0) {
				lastFactor = factor;

				do {
					bigN /= factor;
				} while (bigN % factor == 0);

				maxFactor = (long) Math.sqrt(bigN);
			}
			factor += 2;
		}

		if (bigN == 1) {
			System.out.println(lastFactor);
		} else {
			System.out.println(bigN);
		}
	}

	static boolean isPrime(long n) {
		for (long i = 2; i < n / 2; i++) {
			if (n % i == 0) {
				return false;
			}
		}
		return true;
	}
}
